package io.gitee.yth.design.pattern.test.core.pattern.behavioral.interpreter;

/**
 * 布尔常量
 *
 * @author yth
 * @since 2023-05-01-23:16
 */
public class Constant implements BooleanExp {

    /*
    享元，共享细粒度对象
     */
    public static final Constant TRUE_CONSTANT = new Constant(true);
    public static final Constant FALSE_CONSTANT = new Constant(false);

    private final boolean value;

    private Constant(boolean value) {
        this.value = value;
    }

    @Override
    public boolean evaluate(Context context) {
        return value;
    }

    @Override
    public BooleanExp replace(String var, BooleanExp exp) {
        return value ? TRUE_CONSTANT : FALSE_CONSTANT;
    }

    @Override
    public BooleanExp copy() {
        return value ? TRUE_CONSTANT : FALSE_CONSTANT;
    }
}
